<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Server\AddressServer;
use App\Models\Address;
use App\Services\JsonResponseService;
use Illuminate\Http\Request;


class AddressController extends Controller
{
    public function __construct() {
        $this->server = new AddressServer();
    }

    // 获取省份列表
    public function getCounties()
    {
        $provinces = Address::getProvinces();
        return JsonResponseService::success($provinces,'success',200);
    }

    // 根据省份ID获取城市列表
    public function getCities(Request $request)
    {
        $provinceId = $request->input('provinceId');
        $cities = Address::find($provinceId)->cities()->get();
        return JsonResponseService::success($cities,'success',200);
    }

    // 根据城市ID获取区县列表
    public function getDistricts(Request $request)
    {
        $cityId = $request->input('cityId');
        $districts = Address::find($cityId)->districts()->get();
        return JsonResponseService::success($districts,'success',200);
    }
}
